package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.TrainPlanItem;
import cn.wolfcode.crm.query.TrainPlanItemQueryObject;
import cn.wolfcode.crm.service.ITrainPlanItemService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.LogicException;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("trainPlanItem")
public class TrainPlanItemController {

    @Autowired
    private ITrainPlanItemService service;

    //页面跳转
    @RequestMapping()
    public String list() {
        return "trainPlanItem/list";
    }

    //分页
    @RequestMapping("list")
    @ResponseBody
    public PageResult page(TrainPlanItemQueryObject qo) {
        PageResult page = service.queryPage(qo);
        return page;
    }

    //查询所有
    @RequestMapping("selectAll")
    @ResponseBody
    public List<TrainPlanItem> input() {
        return service.listAll();
    }

    //添加
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(TrainPlanItem entity) {
        JsonResult jr = new JsonResult();
        try {
            service.save(entity);
        } catch (LogicException e) {
            e.printStackTrace();
            jr.setMsg(e.getMessage());
        }
        return jr;
    }

    //修改
    @RequestMapping("update ")
    @ResponseBody
    public JsonResult update(TrainPlanItem entity) {
        JsonResult jr = new JsonResult();
        try {
            service.update(entity);
        } catch (LogicException e) {
            e.printStackTrace();
            jr.setMsg(e.getMessage());
        }
        return jr;
    }

    //删除
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult jr = new JsonResult();
        try {
            service.delete(id);
        } catch (LogicException e) {
            e.printStackTrace();
            jr.setMsg(e.getMessage());
        }
        return jr;
    }

}
